
$(function () {
    $('#xmgl').mouseenter(function () {
        $('#xmgl>ul').stop().show();
    }).mouseleave(function () {
        $('#xmgl>ul').stop().hide();
    });
    $('#yhgl').mouseenter(function () {
        $('#yhgl>ul').stop().show();
    }).mouseleave(function () {
        $('#yhgl>ul').stop().hide();
    });
    $('#zx').click(function () {
        if (window.confirm("确定退出吗？")) {
            location.href = "../login.html";
        }
    });

    $('#check-pass').on('click', function () {
        $.ajax({
            type: 'POST',
            url: 'changePass.php',
            async: false,
            dataType: "json",
            ContentType: "application/x-www-form-urlencoded; charset=UTF-8",

            data: $('#passwdcheck').serialize(),
            success: function (msg) {
                if (msg.status == 1) {
                    alert(msg.mes);
                }
                else if (msg.status == -1) {
                    alert(msg.mes);
                    window.location.reload();
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
    });

    //添加用户
    $('#addTypeUser-bc').on('click', function () {
        $.ajax({
            type: 'POST',
            url: 'doaddUser.php',
            dataType: "json",
            async: false,
            data: $('#adduser').serialize(),// 要提交的表单
            success: function (msg) {
                if (msg.status == "1") {
                    alert(msg.mes);
                    location.href = "user-list.php";
                } else if (msg.status == "-1") {
                    alert(msg.mes);
                    window.location.reload();
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        });
    });

    //修改用户
    $('#alterTypeUser-bc').on('click', function () {
        $.ajax({
            type: 'POST',
            url: 'doeditUser.php',
            async: false,
            dataType: "json",
            data: $('#edituser').serialize(),
            success: function (msg) {
                if (msg.status == "1") {
                    alert(msg.mes);
                    location.href = "user-list.php";
                }
                else if (msg.status == "-1") {
                    alert(msg.mes);
                    window.location.reload();
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }

        });
    });
    //删除用户
    $('#user-del').on('click', function () {
        var id = $('#user-id').text();
        if (window.confirm('确定删除吗？')) {
            $.ajax({
                type: "GET",
                url: 'dodelUser.php',
                async: false,
                dataType: "json",
                data: {
                    id: id
                },
                success: function (msg) {
                    if (msg.status == 1) {
                        alert(msg.mes);
                    }
                    if (result.status == -1) {
                        alert(msg, mes);
                    }
                },
                error: function (result) {
                    alert('请求失败!');
                }
            });
        }
    });
    //添加项目
    $('#addProject-bc').on('click', function () {
        var file = document.getElementById('Enclosure');
        var fileobj = file.files['0'];
        var form = new FormData();
        form.append('pName', document.getElementById('pName').value);
        form.append('pChar', document.getElementById('pChar').value);
        form.append('teacher', document.getElementById('teacher').value);
        form.append('pDesc', document.getElementById('pDesc').value);
        form.append('pRank', document.getElementById('pRank').value);
        form.append('Enclosure', fileobj);
        $.ajax({
            type: "POST",
            url: "doaddPro.php",
            async: false,
            dataType: "json",
            data: form,
            cache: false,
            processData: false,
            contentType: false,
            success: function (msg) {
                if (msg.status == "1") {
                    alert(msg.mes);
                    location.href = "project-list.php";
                } else if (msg.status == "-1") {
                    alert(msg.mes);
                    window.location.reload();
                }
            },
            // error: function (XMLHttpRequest, textStatus, errorThrown) {
            //     alert(XMLHttpRequest.readyState);
            //     alert(textStatus);
            // }
        });
    });
    //修改项目
    $('#alertProject').on('click', function () {

        var file = document.getElementById('Enclosure');
        var fileobj = file.files['0'];
        var form = new FormData();
        //console.log(file)
        // if(file==undefined){
        //     var fileobj=file.files['0'];
        //     form.append('Enclosure', fileobj);
        // } 
        form.append('pname', document.getElementById('pname').value);
        form.append('pid', document.getElementById('pid').value);
        form.append('pChar', document.getElementById('pChar').value);
        form.append('teacher', document.getElementById('teacher').value);
        form.append('pDesc', document.getElementById('pDesc').value);
        form.append('pRank', document.getElementById('pRank').value);
        form.append('Enclosure', fileobj);
        $.ajax({
            type: 'POST',
            url: 'doeditPro.php',
            //async: false,
            dataType: "json",


            cache: false,
            processData: false,
            contentType: false,
            data: form,
            success: function (msg) {
                if (msg.status == "1") {
                    alert(msg.mes);
                    location.href = "project-list.php";
                }
                else if (msg.status == "-1") {
                    alert(msg.mes);
                    window.location.reload();
                }
            },
            // error: function (XMLHttpRequest, textStatus, errorThrown) {
            //     alert(XMLHttpRequest.readyState);
            //     alert(textStatus);
            //     window.location.reload();
            // }
        });
    });
    //删除项目
    $('#project-del').on('click', function () {
        var pid = $('#project-id').text();
        if (window.confirm("确定删除？")) {
            $.ajax({
                type: 'GET',
                url: 'admin/dodelPro.php',
                async: false,
                data:
                {
                    pid: pid
                },
                dataType: JSON,
                success: function (result) {
                    if (result.status == 1) {
                        alert("删除成功!");
                    }
                    if (result.status == -1) {
                        alert("删除失败!");
                    }
                },
                error: function (result) {
                    alert('请求失败!');
                }
            });
        }
    });
    //添加项目成员
    $('#addProjectUser-bc').on('click', function () {
        $.ajax({
            type: "POST",
            url: "doaddPuser.php",
            // async: false,
            dataType: "json",
            data: $('#addpuser').serialize(),
            success: function (msg) {
                if (msg.status == "1") {
                    alert(msg.mes);
                    window.location.href = "alterProjectUser.php";
                } else if (msg.status == "-1") {
                    alert(msg.mes);
                    window.location.reload();
                }
            },
            // error: function (XMLHttpRequest, textStatus, errorThrown) {
            //     alert(XMLHttpRequest.readyState);
            //     alert(textStatus);
            // }
        });
    }
    );
    //删除项目成员
    $('#uid-del').on('click', function () {
        var uid = $('#uid').text();
        if (window.confirm("确定删除？")) {
            $.ajax({
                type: 'GET',
                url: 'admin/dodelPuser.php',
                async: false,
                data:
                {
                    uid: uid
                },
                dataType: JSON,
                success: function (result) {
                    if (result.status == 1) {
                        alert("删除成功!");
                    }
                    if (result.status == -1) {
                        alert("删除失败!");
                    }
                },
                error: function (result) {
                    alert('请求失败!');
                }
            });
        }
    });
});